import com.alibaba.fastjson.JSONObject;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class RMap<T> implements ReSerializeModel{
    private ConcurrentHashMap<String,T> map = new ConcurrentHashMap<String,T>();
    public RMap() {
    }
    public RMap(Map<String, T> map){
        this.map.putAll(map);
    }

    public Map<String, T> getMap(){return this.map; }

    @Override
    public Object reSerialize() {
        return this.map;
    }

    @Override
    public Object toJson() {
        JSONObject json = new JSONObject();
        for(String k : this.map.keySet()){
            Object e = this.map.get(k);
            if(e instanceof ReSerializeModel){
                json.put(k, ((ReSerializeModel) e).toJson());
            } else if(e instanceof String){
                json.put(k, e);
            } else if(e instanceof Integer){
                json.put(k, e);
            }
        }
        return json;
    }

}
